package com.soft.line.util.MP;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description: 日期工具类
 *
 * @version: v1.0.0
 * @author: zlx
 * @date: 2020年3月17日 上午10:41:08
 */
public class DateUtil {

	/**
	 * 获取yyyy-MM-dd格式今日日期字符串
	 * 
	 * @return 例："2020-01-01"
	 */
	public static String getSimpleNowDateStr() {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String dateStr = dateFormat.format(date);
		return dateStr;
	}

	/**
	 * 获取某格式今日日期字符串
	 * 
	 * @return
	 */
	public static String getNowDateStr(String formatStr) {
		DateFormat dateFormat = new SimpleDateFormat(formatStr);
		Date date = new Date();
		String dateStr = dateFormat.format(date);
		return dateStr;
	}
	
	/**
	 * 获取某格式某日期字符串
	 * 
	 * @return
	 */
	public static String getDateStr(Date date,String formatStr) {
		DateFormat dateFormat = new SimpleDateFormat(formatStr);
		String dateStr = dateFormat.format(date);
		return dateStr;
	}

	/**
	 * 判断当前时间是否在[startTime, endTime]区间，注意时间格式要一致
	 * 
	 * @param nowTime
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
		if (nowTime.getTime() == startTime.getTime() || nowTime.getTime() == endTime.getTime()) {
			return true;
		}

		Calendar date = Calendar.getInstance();
		date.setTime(nowTime);

		Calendar begin = Calendar.getInstance();
		begin.setTime(startTime);

		Calendar end = Calendar.getInstance();
		end.setTime(endTime);

		if (date.after(begin) && date.before(end)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 获取当前时间秒值
	 * 
	 * @return
	 */
	public static long getNowTimeSecond() {
		return new Date().getTime() / 1000;
	}


	/**
	 * 获取yyyyMMddHHmmssSSS格式今日日期字符串
	 *
	 * @return 例："20200326190038998"
	 */
	public static String getSimpleDayTimeStr() {
		DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		Date date = new Date();
		String dateStr = dateFormat.format(date);
		return dateStr;
	}

}
